package com.example.demo;

import lombok.Data;
import lombok.RequiredArgsConstructor;

import lombok.extern.slf4j.Slf4j;

import java.util.List;

/**
 * @author jiangjinwu
 * @version 1.0
 * @since 2025/10/22 14:07
 */

@Slf4j
@Data
public class PageResult<T> {
    private int current;
    private int size;
    private int pages;
    private int total;
    List<T> records;

    public PageResult(int page, int pageSize, int total) {
        this.current = Math.max(page, 0);
        this.size = pageSize <= 0 ? 20 : pageSize;
        this.pages = totalPage(total, pageSize);
        this.total = total;
    }
    public static int totalPage(long totalCount, int pageSize) {
        return pageSize == 0 ? 0 : Math.toIntExact(totalCount % (long)pageSize == 0L ? totalCount / (long)pageSize : totalCount / (long)pageSize + 1L);
    }
}
